package com.internetCafes.spms.web.sys.service.impl;

import com.internetCafes.spms.core.model.pageModel.DataGrid;
import com.internetCafes.spms.web.certificate.vo.CertificateInfoVo;
import com.internetCafes.spms.web.sys.mapper.PolicyInfoMapper;
import com.internetCafes.spms.web.sys.model.PolicyInfo;
import com.internetCafes.spms.web.sys.service.PolicyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author LinYe
 * @date 2020/10/29
 */
@Service("PolicyInfoService")
public class PolicyInfoServiceImpl implements PolicyInfoService {

    @Autowired
    PolicyInfoMapper policyInfoMapper;

    @Override
    public int savePolicy(PolicyInfo policyInfo) {
        return policyInfoMapper.insert(policyInfo);
    }

    @Override
    public int deletePolicy(Long id) {
        return policyInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updatePolicy(PolicyInfo policyInfo) {
        return policyInfoMapper.updateByPrimaryKey(policyInfo);
    }

    @Override
    public PolicyInfo getPolicyDetail(Long id) {
        return policyInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {
        params.put("page", (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize);
        params.put("rows", pageSize);
        List<PolicyInfo> policyInfoList = policyInfoMapper.selectByParams(params);
        long count = policyInfoMapper.countByParams(params);
        return new DataGrid(policyInfoList, count, pageSize, pageNo);
    }
}
